package com.baiyang.server.service.system.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baiyang.server.dao.system.UserDao;
import com.baiyang.server.model.system.User;
import com.baiyang.server.redis.RedisUtil;
import com.baiyang.server.service.impl.BaseServiceImpl;
import com.baiyang.server.service.system.UserService;

/**
 * 
 * @author XVX
 * BY: @Primary 注解帮助生命@Autowired优先注入的实列
 */
@Service	
public class UserServiceImpl extends BaseServiceImpl<UserDao, User>implements UserService{
	@Autowired
	private RedisUtil redisUtil = null;
	@Autowired
	private UserDao userDao = null;

	/**
	 * 根绝userName获取用户信息
	 */
	@Override
	public User selectOneByUserName(String username) {
		if(username == null) {
			return null; 
		}
		User user = (User) redisUtil.hget("user", username);
		if(user == null) {
			user = new User();
			user.setUserName(username);
			user = userDao.selectOne(user);
			if(user != null) {
				redisUtil.hset("user", username, user);
			}
		}
		return user;
	}
	
}
